/*
 * Copyright (C) 2021 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.onlylemi.mapview.slice;

import com.onlylemi.mapview.ResourceTable;
import com.onlylemi.mapview.TestData;
import com.onlylemi.mapview.ToastUtil;
import com.onlylemi.mapview.library.MapView;
import com.onlylemi.mapview.library.MapViewListener;
import com.onlylemi.mapview.library.layer.MarkLayer;
import com.onlylemi.mapview.library.utils.MapUtils;
import ohos.aafwk.ability.AbilitySlice;
import ohos.aafwk.content.Intent;
import ohos.agp.components.Text;
import ohos.agp.utils.Point;
import ohos.agp.window.dialog.ToastDialog;
import ohos.media.image.PixelMap;

import java.util.List;

public class MarkLayerTestSlice extends AbilitySlice {

    private MapView mapView;
    private MarkLayer markLayer;

    @Override
    protected void onStart(Intent intent) {
        super.onStart(intent);
        super.setUIContent(ResourceTable.Layout_slice_mark_layer_test);

        Text tvTitle = (Text) findComponentById(ResourceTable.Id_tv_title);
        tvTitle.setText("MarkLayerTest");

        mapView = (MapView) findComponentById(ResourceTable.Id_mapview);
        PixelMap bitmap = MapUtils.getPixelMap(this, ResourceTable.Media_map);
        mapView.loadMap(bitmap);
        mapView.setMapViewListener(new MapViewListener() {
            @Override
            public void onMapLoadSuccess() {
                List<Point> marks = TestData.getMarks();
                final List<String> marksName = TestData.getMarksName();
                markLayer = new MarkLayer(mapView, marks, marksName);
                markLayer.setMarkIsClickListener(new MarkLayer.MarkIsClickListener() {
                    @Override
                    public void markIsClick(int num) {
                        ToastUtil.show(marksName.get(num) + " is " + "selected");
                    }
                });
                mapView.addLayer(markLayer);
                mapView.refresh();
            }

            @Override
            public void onMapLoadFail() {
            }
        });
    }
}
